local thbattle__zaomiao_qiji = fk.CreateSkill {

  name = "thbattle__zaomiao_qiji",

  tags = {},

}



thbattle__zaomiao_qiji:addEffect("active", {
  prompt = function(self, player, selected_cards, selected_targets)
    return "#thbattle__zaomiao_qiji:::" .. player:usedSkillTimes(thbattle__zaomiao_qiji.name, Player.HistoryPhase) + 1
  end,
  target_filter = Util.FalseFunc,
  card_num = function()
    return Self:usedSkillTimes("thbattle__zaomiao_qiji", Player.HistoryPhase) + 1
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected < player:usedSkillTimes("thbattle__zaomiao_qiji", Player.HistoryPhase) + 1
  end,
  anim_type = "drawcard",
  can_use = function(self, player)
    return #player:getCardIds("he") >= player:usedSkillTimes(thbattle__zaomiao_qiji.name, Player.HistoryPhase) + 1
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:throwCard(effect.cards, thbattle__zaomiao_qiji.name, player, player)
    player:drawCards(1, thbattle__zaomiao_qiji.name)
    if player:usedSkillTimes(thbattle__zaomiao_qiji.name, Player.HistoryPhase) == 3 then
      local target_players = table.filter(room.alive_players, function(p)
        return p:isWounded()
      end)
      if #target_players > 0 then
        local target = room:askForChoosePlayers(player, table.map(target_players, Util.IdMapper), 1, 1,
          "#thbattle__zaomiao_qiji-choose_player", thbattle__zaomiao_qiji.name, true)
        if #target > 0 then
          room:recover({
            who = room:getPlayerById(target[1]),
            num = 1,
            recoverBy = player,
            skillName = thbattle__zaomiao_qiji.name
          })
        end
      end
    end
  end,
})

return thbattle__zaomiao_qiji
